#include "appConfig.h"

#include <iostream>
#include <fstream>

using namespace std;
using namespace nlohmann;

SINGLETON_IMPL(AppConfig)


AppConfig::AppConfig() : m_sys(json::object()), m_user(json::object())
{
    init();
}

void AppConfig::init()
{
    // 1. 读取 sys.json
    ifstream f("/home/li/stone-book/code/BookServer/build/bin/config/sys.json");
    cout << "read sys.json\n";
    if(f.is_open()) {
        string data;
        f >> data;
        cout << data;
        m_sys = json::parse(data.c_str());

        f.close();
    }
    else {
        cerr << "open sys.json failed.\n";
    }

    // 2. 读取 user.json
    f.open("/home/li/stone-book/code/BookServer/build/bin/config/user.json", ios::in);
    cout << "read user.json\n";
    if(f.is_open()) {
        string data;
        f >> data;
        cout << data;
        m_user = json::parse(data.c_str());

        f.close();
    }
    else {
        cerr << "open user.json failed.\n";
    }
}

void AppConfig::saveConfig()
{
}
